<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include "bantuan.php";

class Practice_Test extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */

	function __construct(){
        // Call the Model constructor
        parent::__construct();
		$this->load->model('Practice_Models');
    }

	public function index()
	{	
		$cb= new Bantuan();
		
		$page=$this->input->get('per_page');
		$data['query'] = $this->Practice_Models->getKaryawan(null,$page); 
		$data['data'] = array('111','222','333','444');

		$data['total']=$this->Practice_Models->countKaryawan();

		$data['paging']=$cb->paging('http://localhost/ci-tes/index.php/Practice_Test/index?',$this->Practice_Models->countKaryawan(),5);		

		$data['page'] = $page!='' ? $page+1 :1;

		$param['title'] = 'INDEX';
		$param['i'] = $this->load->view('body_bebas', $data, true);
		$this->load->view('bebas',$param);
	}

	public function addForm(){
		$nama = array(
              'name'        => 'nama',
              'id'          => 'nama',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:20%',
            );
		
		$umur = array(
              'name'        => 'umur',
              'id'          => 'umur',
              'maxlength'   => '2',
              'size'        => '50',
              'style'       => 'width:10%',
            );


		$i=$this->input->get('id');
	
		if($i != ''){
			$query = $this->Practice_Models->getKaryawan($i,null);
			foreach($query as $row){
				$nama['value'] = $row->karyawan_nama;
				$umur['value'] = $row->karyawan_umur;
			
				$lajang = FALSE;
				$menikah =FALSE;
			//$temp = 'LAJANG';
			//	die($row->karyawan_);
			//	if(strcasecmp($temp,$row->karyawan_umur)==0)
				if('LAJANG' == $row->karyawan_status)
					$lajang=TRUE;
				else
					$menikah=TRUE;

				$data['radio'] = array(
					'lajang'=>form_radio('status', 'lajang', $lajang), 
					'menikah'=>form_radio('status', 'menikah', $menikah)
				);
			}
			$hidden = array('karyawan_id' => $i);
			$data['hidden'] = form_hidden($hidden);
			$data['submit'] = form_submit('Practice_Test/update', 'UPDATE');
			$data['form'] = 'Practice_Test/update';
		}else{
			$data['radio'] = array(
					'lajang'=>form_radio('status', 'lajang'), 
					'menikah'=>form_radio('status', 'menikah')
				);

			$data['submit'] = form_submit('Practice_Test/insert', 'INSERT');
			$data['form'] = 'Practice_Test/insert';
		}
		$data['data'] = array(
				'nama'=>form_input($nama),
				'umur'=>form_input($umur)
			);

		$param['title'] = 'ADD FORM';
		$param['i'] = $this->load->view('add_form', $data, true);

		$this->load->view('bebas',$param);
	}

	public function insert(){
		//$this->load->database();
		//$something = $this->input->post('something');

		$data = array(
		   'karyawan_nama' => $this->input->post('nama') ,
		   'karyawan_umur' => $this->input->post('umur') ,
		   'karyawan_status' => $this->input->post('status')
		);

		$this->Practice_Models->insertKaryawan($data);

		$this->index();
	//	die('kena deh');
		//die('insert bro');
	}

	public function update(){
		$data = array(
           'karyawan_nama' => $this->input->post('nama') ,
		   'karyawan_umur' => $this->input->post('umur') ,
		   'karyawan_status' => $this->input->post('status'),
		   'karyawan_id' => $this->input->post('karyawan_id')
       	);
	//	die($data['karyawan_id']);
		$this->Practice_Models->updateKaryawan($data);

		$this->index();
	}

	public function delete(){
		$id=$this->input->get('id');
		$this->Practice_Models->deleteKaryawan($id);

		$this->index();
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>